package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.CheckPhoneTokenDto;
import com.ewhale.feitengguest.view.user.mine.ResetPhoneView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

public class ResetPhonePresenter extends IPresenter {
    private String user_checkphone = "app/account/checkPhone.json";
    private String shop_checkphone = "app/shop/checkPhone.json";
    public void getCode(String sessionId,String phone) {
        mView.showProLoading();
        request(1, ApiHelper.AUTH_API.getCode(sessionId,phone, "3"), null);
    }

    public void checkPhone(int apptype,String phone, String phoneCode) {
        mView.showProLoading();
        request(2, ApiHelper.AUTH_API.checkPhone(apptype == 1? user_checkphone : shop_checkphone,phone, phoneCode), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((ResetPhoneView) mView).getCodeSuccess();
                break;
            case 2:
                ((ResetPhoneView) mView).checkPhone((CheckPhoneTokenDto) result);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
